#include "SocketsOpsExt.h"
#include "muduo/base/Types.h"
#include "muduo/base/Logging.h"
#include "muduo/net/Endian.h"

#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <assert.h>
#include <sys/uio.h>

using namespace muduo;
using namespace muduo::net;

int sockets::createNonblockingSocket(sa_family_t family)
{
#if VALGRIND // a kind of memory test tool
	int sockfd = ::socket(family, SOCK_STREAM, IPPROTO_TCP);
#endif
	int sockfd = ::socket(family, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, IPPROTO_TCP);
	return sockfd;
}

int sockets::bind(int sockfd, const struct sockaddr* addr)
{
	int ret = ::bind(sockfd, addr, static_cast<socklen_t>(sizeof(struct sockaddr_in6)));
	return ret;
}

int sockets::listen(int sockfd)
{
	int ret = ::listen(sockfd, SOMAXCONN);
	return ret;
}
